<include file="__THEME__/header" />
<link rel="stylesheet" href="../Public/poll.css" type="text/css" media="screen" charset="utf-8" />
<link href="__PUBLIC__/js/pagination/pagination.css" rel="stylesheet" type="text/css" />
<include file="../Public/_mainNav" />
<div class="content">
  <!-- 内容 begin  -->
  <div class="main no_l">
    <!-- 右侧内容 begin  -->
    <div class="mainbox">
    <div class="mainbox_R">
        <div class="right_box alC mt10"><a href="{:U('vote/Index/addPoll')}"><img src="../Public/images/add_btn.gif" /></a></div>
		<include file="../Public/_isHotList" />	
      </div>
      
      <div class="mainbox_C">
    <div class="page_title" style="width:auto;">
      <!-- page_title begin -->
      <h2><span class="right f12px fn"></span>发起{$ts['app']['app_alias']}</h2>
    </div>
    <!-- page_title end -->
    <style>
        .choice-list li{display:block;}
        </style>
    <script>
            $(function(){
                $("#tog_explain").toggle(function(){
                    $("#vote_explain").show('fast');
                    $(this).text("隐藏{$ts['app']['app_alias']}详细说明");
                },function(){
                    $("#vote_explain").hide('fast');
                    $(this).text("添加{$ts['app']['app_alias']}详细说明");
                });

                //截止时间
                $("#year option[value='{$date.year}']").attr('selected',true);
                $("#month option[value='{$date.month|intval}']").attr('selected',true);
				day();
                $("#day option[value='{$date.day|intval}']").attr('selected',true);
                $("#hour option[value='{$date.hour|intval}']").attr('selected',true);
            });

			//判断月份天数
			function day(){
				var days=Array(31,28,31,30,31,30,31,31,30,30,30,31);
				var month = parseInt($( '#month' ).val());
				var day = parseInt($( '#day' ).val());
				var html = null;
				if(month == 2){
					var year = parseInt($( '#year' ).val());
					days[1] = (year%100!=0&&year%4==0 || year%400==0)?29:28;
				}
				for(i=1;i<=days[month-1];i++){
					html+='<option value="'+i+'">'+i+'</option>';
				}
				$('#day').html(html);
                $("#day option[value="+day+"]").attr('selected',true);
			}

          	function check_vote() {
								var title = $.trim($("#title").val());
								if(!title){
									ui.error("{$ts['app']['app_alias']}主题不能为空!");
									return false;
								}
								var flag = 0;
								$(".vote_opt").each(function (i) {
									if($.trim($(this).val())) flag++;									
								})
								if(flag<2){
									ui.error("至少填写2个选项!");
									return false;
								}
                var type = $( '#type' ).val();
                if( type > flag-1 ){
                  ui.error( '{$ts['app']['app_alias']}选项不得少于可选选项限数' ) ;
                  return false;
                }

							}


            flag = 1;
            var num_limit=10;
            function more(){
              var new_vote = $( '#vote_default' ).clone();
              if( flag == 1 ){
                $( '.vote_opt' ).each( function( i ){
                   flag++;
                });
              }
              new_vote.children( '.alR' ).html( "候选项"+flag+"：" );
              new_vote.find( 'input' ).val( '' );
              flag++;
              $( '#vote_more_options' ).before( new_vote );
               // $("#more_options").show();
               // $("#add_more").hide();
              num_limit--;
              if( num_limit == 0 ){
                $( '#add_more' ).hide();
                return;
              }
            }
        </script>
    <div class="pollBox">
      
        <form method="post" action="{:U('vote/Index/add')}" onsubmit="return check_vote() ">
          <div class="LogList">
          <ul class="edit">
            <li>
              <div class="left alR" style="width: 15%;">{$ts['app']['app_alias']}主题：</div>
              <div class="left" style="width: 85%;">
                <input id="title" name="title" type="text" class="text" style="width:70%" onblur="this.className='text'" onfocus="this.className='text2'" maxlength="30"/>
                <a id="tog_explain" href="javascript:void(0)">添加{$ts['app']['app_alias']}详细说明</a> </div>
              <div class="c"></div>
            </li>
            <li id="vote_explain" style="display:none;">
              <div class="left alR" style="width: 15%;">详细说明：</div>
              <div class="left" style="width: 85%;">
                <textarea name="explain" rows="5" class="text"  style="width:90%" onfocus="this.className='text2';" onblur="this.className='text';"></textarea>
              </div>
              <div class="c"></div>
            </li>
            <li id="vote_default">
              <div class="left alR" style="width: 15%;">候选项1：</div>
              <div class="left" style="width: 85%;">
                <input name="opt[]" type="text" class="text vote_opt" id="textfield3" style="width:70%" onblur="this.className='text vote_opt'" onfocus="this.className='text2 vote_opt'" maxlength="30"/>
              </div>
              <div class="c"></div>
            </li>
            <li>
              <div class="left alR" style="width: 15%;">候选项2：</div>
              <div class="left" style="width: 85%;">
                <input name="opt[]" type="text" class="text vote_opt" id="textfield3" style="width:70%" onblur="this.className='text vote_opt'" onfocus="this.className='text2 vote_opt'" maxlength="30"/>
              </div>
              <div class="c"></div>
            </li>
            <li>
              <div class="left alR" style="width: 15%;">候选项3：</div>
              <div class="left" style="width: 85%;">
                <input name="opt[]" type="text" class="text vote_opt" id="textfield3" style="width:70%" onblur="this.className='text vote_opt'" onfocus="this.className='text2 vote_opt'" maxlength="30"/>
              </div>
              <div class="c"></div>
            </li>
            <li>
              <div class="left alR" style="width: 15%;">候选项4：</div>
              <div class="left" style="width: 85%;">
                <input name="opt[]" type="text" class="text vote_opt" id="textfield3" style="width:70%" onblur="this.className='text vote_opt'" onfocus="this.className='text2 vote_opt'" maxlength="30"/>
              </div>
              <div class="c"></div>
            </li>
            <li>
              <div class="left alR" style="width: 15%;">候选项5：</div>
              <div class="left" style="width: 85%;">
                <input name="opt[]" type="text" class="text vote_opt" id="textfield3" style="width:70%" onblur="this.className='text vote_opt'" onfocus="this.className='text2 vote_opt'" maxlength="30"/>
              </div>
              <div class="c"></div>
            </li>
            <li>
              <div class="left alR" style="width: 15%;">候选项6：</div>
              <div class="left" style="width: 85%;">
                <input name="opt[]" type="text" class="text vote_opt" id="textfield3" style="width:70%" onblur="this.className='text vote_opt'" onfocus="this.className='text2 vote_opt'" maxlength="30"/>
              </div>
              <div class="c"></div>
            </li>
            <li>
              <div class="left alR" style="width: 15%;">候选项7：</div>
              <div class="left" style="width: 85%;">
                <input name="opt[]" type="text" class="text vote_opt" id="textfield3" style="width:70%" onblur="this.className='text vote_opt'" onfocus="this.className='text2 vote_opt'" maxlength="30"/>
              </div>
              <div class="c"></div>
            </li>
            <li>
              <div class="left alR" style="width: 15%;">候选项8：</div>
              <div class="left" style="width: 85%;">
                <input name="opt[]" type="text" class="text vote_opt" id="textfield3" style="width:70%" onblur="this.className='text vote_opt'" onfocus="this.className='text2 vote_opt'" maxlength="30"/>
              </div>
              <div class="c"></div>
            </li>
            <li>
              <div class="left alR" style="width: 15%;">候选项9：</div>
              <div class="left" style="width: 85%;">
                <input name="opt[]" type="text" class="text vote_opt" id="textfield3" style="width:70%" onblur="this.className='text vote_opt'" onfocus="this.className='text2 vote_opt'" maxlength="30"/>
              </div>
              <div class="c"></div>
            </li>
            <li>
              <div class="left alR" style="width: 15%;">候选项10：</div>
              <div class="left" style="width: 85%;">
                <input name="opt[]" type="text" class="text vote_opt" id="textfield3" style="width:70%" onblur="this.className='text vote_opt'" onfocus="this.className='text2 vote_opt'" maxlength="30"/>
              </div>
              <div class="c"></div>
            </li>
            <li id="vote_more_options" style="display:none;">
              <div class=""></div>
            </li>
            <li>
              <div class="left alR" style="width: 15%;">&nbsp;</div>
              <div class="left" style="width: 85%;"><a id="add_more" href="javascript:more()">增加更多候选项</a></div>
              <div class="c"></div>
            </li>
            <li>
              <div class="left alR" style="width: 15%;">可投选项：</div>
              <div class="left" style="width: 85%;">
                <select id="type" name="type" class="text mr5">
                  <option value="0">单选</option>
				  <php>for($i=1;$i<20;$i++){</php>
                 	 <option value="{$i}">可多选，最多{$i+1}项</option>
				  <php>}</php>			
                </select>
              </div>
              <div class="c"></div>
            </li>
            <li>
              <div class="left alR" style="width: 15%;">截止时间：</div>
              <div class="left" style="width: 85%;">
                <select name="year" id="year" class="text mr5">
                <php>$startY=date('Y',time());
					 for($i=$startY;$i<$startY+5;$i++){</php>
					<option value="{$i}">{$i}</option>
				<php>}</php>
                </select>
                年
                <select name="month" id="month" class="text mr5">
				  <php>for($i=1;$i<=12;$i++){</php>
					<option value="{$i}">{$i}</option>
				  <php>}</php>
                </select>
                月
                <select name="day" id="day" class="text mr5">
                  <option value="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
                </select>
                日
                <select name="hour" id="hour" class="text mr5">
				  <php>for($i=0;$i<=23;$i++){</php>
					<option value="{$i}">{$i}</option>
				  <php>}</php>
                </select>
                时 </div>
              <div class="c"></div>
            </li>
            <li style="border-bottom:0;">
              <div class="left alR" style="width: 15%;">&nbsp;</div>
              <div class="left" style="width: 85%;">
                <input type="submit" class="btn_b" value="发起{$ts['app']['app_alias']}" />
              </div>
              <div class="c"></div>
            </li>
          </ul>
          </div>
        </form>
      
      <!-- LogList end  -->
    </div>
    <div class="c"></div>
    </div>
  </div>
  <div class="c"></div>
  </div>
  <!-- 画布 end  -->
</div>
<!-- 内容 end -->
<include file="__THEME__/footer" />
<script>
//检测月份选项变动
$('#month').change(function() {
	day();
});
//检测年份选项变动
$('#year').change(function() {
	day();
});
</script>